﻿/*********************************************************************
 *
 *                             NOTICE
 *               COPYRIGHT (c) 2012 Panoscopix Software, Inc.
 *                UNPUBLISHED - ALL RIGHTS RESERVED
 * 
 *      This program is confidential, proprietary, and a trade
 *   secret of Panoscopix Software, Inc. The receipt or possession of
 *     this program does not convey any rights to reproduce or
 *      disclose its contents, or to manufacture, use, or sell
 *       anything that it may describe, in whole or in part, 
 *   without the specific written consent of Panoscopix Software, Inc.
 *
 * An in-memory FileSystem, with some initial files in the root directory.
 * 
 *******************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FileSystem;
using FileSystem.impl;

namespace FileSystem.Impl
{
    class FSFileSystem : IFSFileSystem
    {
	    private static FSFileSystem instance;
	    private IFSDirectory root;
	    private int nextNodeId;
        private List<Result> asyncResults;
        private string activeMacroName;
        private IDictionary<string, IMacroDefintion> macroDefintion;
	
	    private FSFileSystem() {
            buildData();
		    nextNodeId = 100;
	    }
	
	    public static FSFileSystem getInstance() {
		    if (null == instance) {
			    instance = new FSFileSystem();
		    }
		    return instance;
	    }
	
	    public IFSDirectory getRoot() {
		    if (null == root) {
			    buildData();
		    }
		    return root;
	    }
	
	    public String getNextNodeId() {
            int id = nextNodeId++;
		    return id.ToString();
	    }

        public List<Result> AsyncResults
        {
            get
            {
                if(asyncResults == null)
                {
                    asyncResults = new List<Result>();
                }
                return asyncResults;
            }
        }
        public string ActiveMacroName
        {
            get
            {
                return this.activeMacroName;
            }
            set
            {
                this.activeMacroName = value;
            }
        }

        public IDictionary<string, IMacroDefintion> MacroDefintion
        {
            get
            {
                if (macroDefintion == null)
                {
                    macroDefintion = new Dictionary<string, IMacroDefintion>();
                }
                return macroDefintion;
            }
        }

	
	    public INodeMetaDataVO getMetaDataForEmptyNode(String name) {
		    String id = getNextNodeId();
		    DateTime creation = DateTime.Now; //now
		    int size = 0;
		    return new NodeMetaData(id, name, size, creation);		
	    }
	
	    private void buildData() {
		    DataBuilder builder = DataBuilder.getInstance();
            INodeMetaDataVO metaData = getMetaDataForEmptyNode("");  //root has empty name.
		    CurrentDirectory = root = new FSDirectory(metaData);
	    }

        /// <summary>
        /// Gets the current directory.
        /// </summary>
        public IFSDirectory CurrentDirectory
        {
            get;
            set;
        }

        
    }
}
